<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div id="page-content">
    <div class="row">

        <div class="col-lg-12">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">发文管理</h3>
                </div>
                <div class="panel-body">
                    <div class="form-inline">
                        <div class="row">
                            <div class="col-sm-12 table-toolbar-left">
                                <btn id="btn_add_outfile" class="btn btn-primary btn-sm">
                                    <i class="ti-plus"> </i> 新建发文申请表
                                </btn>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table id="outfile_running_table"></table>
                        <div id="outfile_running_page"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script>

    $(function(){

        init_grid_outfile();

    });

    function init_grid_outfile() {

        __init_jqgrid('outfile_running_table', 'outfile_running_page',
                '<%=path%>/activiti/outfile/list',
                ['发文类别', '文件编号', '发文标题', '发文时间', '修订次数','文档状态', '操作', 'id'],
                [
                    {name: 'dictItemName', index: 'dictItemName', width: 60, sortable: true, search: false},
                    {name: 'fileNo', index: 'fileNo', width: 60, sortable: true, search: false},
                    {name: 'name', index: 'name', width: 120, sortable: false, stype: 'text', searchoptions: {sopt: ['cn']}},
                    {name: 'datPulished', index: 'datPulished', width: 60, sortable: false, search: false},
                    {name: 'numRevise', index: 'numRevise', width: 40, sortable: false, search: false},
                    {name: 'txtStatus', index: 'txtStatus', width: 40, sortable: false, search: false},
                    {name: 'act', index: 'act', width: 200, fixed: true, sortable: false, search: false, formatter: actFormat},
                    {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
                ],
                true,
                {
                    postData: {catalog: 0x01}
                }
        );

    }

    function actFormat(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_outfile_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button>';
        cellvalue += '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_outfile_revise(\'' + id + '\');"><i class="fa fa-check"> </i> 修订</button>';
        cellvalue += '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_outfile_invalid(\'' + id + '\');"><i class="fa fa-close"> </i> 失效</button>';
        return cellvalue;
    }

    function fn_outfile_read(id) {
        loadURL('<%=path%>/activiti/outfile/read/'+id, $('#page-content'));
    }

    $("#btn_add_outfile").click(function(){
        loadURL('<%=path%>/activiti/outfile/create', $('#page-content'));
    });

    function fn_outfile_revise(id) {
        __confirm_dialog("确认？", "确定要修订该文件吗？", function () {
            var url = '<%=path%>/activiti/outfile/edit/' + id;
            loadURL(url, $('#page-content'));
        });
    }

    function fn_outfile_invalid(id) {
        __confirm_dialog("确认？", "确定要使该文件失效吗？", function () {
            var url = '<%=path%>/activiti/outfile/invalid/'+id;
            __ajax_post(url, null, function(data) {
                __toastr(data);
                if(data.state == 1) {
                    // 刷新grid
                    $('#outfile_running_table').trigger('reloadGrid');
                }
            });
        });
    }
</script>